<?php

namespace App\Models\Labaicai;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Labaicai\FooodCategories
 *
 * @property int $id
 * @property string|null $name
 * @property int|null $sort
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property int|null $type 1食物  2运动
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Labaicai\Fooods[] $foods
 * @property-read int|null $foods_count
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Labaicai\FooodCategories filter()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Labaicai\FooodCategories newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Labaicai\FooodCategories newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Labaicai\FooodCategories query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Labaicai\FooodCategories whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Labaicai\FooodCategories whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Labaicai\FooodCategories whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Labaicai\FooodCategories whereSort($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Labaicai\FooodCategories whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Labaicai\FooodCategories whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class FooodCategories extends Model
{
    protected $fillable = [
        'id', 'name', 'sort'
    ];
    protected $table = 'food_categories';

    public function foods()
    {
        return $this->hasMany(Fooods::class, 'food_category_id');
    }

    public function scopeFilter($query)
    {
        $type = request('type') ? request('type') : 1;
        return $query->where('type', $type);
    }
}
